let form = layui.form;
form.verify({
  user: [/^\w{2,10}$/, '用户名必须是2~10位'],
  pass: [/^\S{6,12}$/, '密码必须是6~12位'],
  email: [/^([0-9A-Za-z\-_\.]+)@([0-9a-z]+\.[a-z]{2,3}(\.[a-z]{2})?)$/, '邮箱格式错误'],
  //两次密码不一致判断
  same: function (val) {
    //当前的确认密码和密码的值不一样时  直接返回
    if (val !== $('input').eq(2).val()) {
      return '两次新密码不一致';
    }
  },
});

//给表单一个提交事件  
$('.addjs').on('submit', function (e) {
  //阻止默认行为
  e.preventDefault();
  //收集表单内容
  let data = $(this).serialize()
  //ajax请求
  $.ajax({
    type: 'POST',
    url: '/admin/users',
    data: data,
    // headers: {
    //   Authorization: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWQiOjEsImlhdCI6MTYzMjAyMjg0MywiZXhwIjoxNjMyMTk1NjQzfQ.Eomw3ggpJ5QpNH7FPA8TjXaxN_ZP5e16TLeH9Rgx1sQ'
    // },
    success: (res) => {
      console.log(res);
      layer.msg(res.message);
      if (res.status === 0) {
        layer.msg(res.message);
      } else if (res.status === 1) {
        layer.msg(res.message);
      } else if (res.status === -1) {
        layer.msg(res.message);
      }
    }
  })
  $('.addcss').val('')
})